#! /usr/bin/env python3
from PIL import Image
from glob import glob
import os
from tqdm import tqdm
import argparse

def convertImages(dir1, dir2):
    pathList = glob(os.path.join(dir1, '*'))
    for i in tqdm(range(len(pathList)), ncols=100):
        path1 = pathList[i]
        filename = os.path.split(path1)[-1]
        path2 = os.path.join(dir2, filename)
        image = Image.open(path1).convert('L').convert('RGB')
        image.save(path2)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='图片灰度化工具')
    parser.add_argument('source', metavar='原始图片目录', type=str,
                        help='原始图片文件所在目录')
    parser.add_argument('designation', metavar='生成图片目录', type=str,
                        help='生成图片文件所在目录')

    args = parser.parse_args()
    convertImages(args.source, args.designation)
